Skip to content

audit#2

Open
DiabeticTurtle wants to merge 411 commits into
developmentfrom
main
Open

audit#2
DiabeticTurtle wants to merge 411 commits into
developmentfrom
main

Conversation

@DiabeticTurtle

Copy link
Copy Markdown
Owner

No description provided.

@code-review-doctor code-review-doctor Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good. Worth considering though. View full project report here.


info_json = Path(__file__).parent.resolve() / "info.json"
with open(info_json, encoding="utf-8") as f:
__plugin_info__ = json.loads(f.read())

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
__plugin_info__ = json.loads(f.read())
__plugin_info__ = json.load(f)

This can be simplified by using json.load(...). More details.

if args["nick"]:
matched_here = []
for user in matched:
if any([user.nick and piece.lower() in user.nick.lower() for piece in args["nick"]]):

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if any([user.nick and piece.lower() in user.nick.lower() for piece in args["nick"]]):
if any(user.nick and piece.lower() in user.nick.lower() for piece in args["nick"]):

any can take a generator, so constructing a list first may be unnecessary. Read more.

if args["name"]:
matched_here = []
for user in matched:
if any([piece.lower() in user.display_name.lower() for piece in args["name"]]):

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if any([piece.lower() in user.display_name.lower() for piece in args["name"]]):
if any(piece.lower() in user.display_name.lower() for piece in args["name"]):

As above, Constructing a list first may be unnecessary.

if args["not-nick"]:
matched_here = []
for user in matched:
if not any([user.nick and piece.lower() in user.nick.lower() for piece in args["not-nick"]]):

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if not any([user.nick and piece.lower() in user.nick.lower() for piece in args["not-nick"]]):
if not any(user.nick and piece.lower() in user.nick.lower() for piece in args["not-nick"]):

As above, Constructing a list first may be unnecessary.

if args["not-user"]:
matched_here = []
for user in matched:
if not any([piece.lower() in user.name.lower() for piece in args["not-user"]]):

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if not any([piece.lower() in user.name.lower() for piece in args["not-user"]]):
if not any(piece.lower() in user.name.lower() for piece in args["not-user"]):

Again, Constructing a list first may be unnecessary.

if args["not-discrim"]:
matched_here = []
for user in matched:
if not any([disc == int(user.discriminator) for disc in args["not-discrim"]]):

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if not any([disc == int(user.discriminator) for disc in args["not-discrim"]]):
if not any(disc == int(user.discriminator) for disc in args["not-discrim"]):

Same as above: Constructing a list first may be unnecessary.


info_json = Path(__file__).parent.resolve() / "info.json"
with open(info_json, encoding="utf-8") as f:
__plugin_info__ = json.loads(f.read())

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
__plugin_info__ = json.loads(f.read())
__plugin_info__ = json.load(f)

This can be simplified by using json.load(...). Explained here.

Comment thread moderation/moderation.py

info_json = Path(__file__).parent.resolve() / "info.json"
with open(info_json, encoding="utf-8") as f:
__plugin_info__ = json.loads(f.read())

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
__plugin_info__ = json.loads(f.read())
__plugin_info__ = json.load(f)

This can be simplified by using json.load(...). More details.

Comment thread moderation/moderation.py
try:
user = await self.bot.get_or_fetch_user(user_id)
except (discord.NotFound, Exception):
raise commands.BadArgument('"{}" not found. Invalid user ID.'.format(user_id))

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

f-string is easier to read, write, and less computationally expensive than legacy string formatting. More details.

Comment thread moderation/moderation.py
except Exception as exc:
err = f"{type(exc).__name__}: {str(exc)}"
raise commands.BadArgument(
"Error renaming {name}#{discrim}.\n```Haskell\n{error}\n```".format(

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As above, Consider using f-string instead.

@code-review-doctor code-review-doctor Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Worth considering. View full project report here.

Comment thread tagsDev/models.py Outdated
from discord.ext import commands


class SafeFormat(object):

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
class SafeFormat(object):
class SafeFormat:

SafeFormat inherits from object by default, so explicitly inheriting from object is redundant. Removing it keeps the code simpler. Read more.

Comment thread tagsDev/models.py Outdated
self.__dict = kw

def __getitem__(self, name):
return self.__dict.get(name, SafeString('{%s}' % name))

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
return self.__dict.get(name, SafeString('{%s}' % name))
return self.__dict.get(name, SafeString(f'{{{name}}}'))

f-string is easier to read, write, and less computationally expensive than legacy string formatting. More.

Comment thread tagsDev/models.py Outdated
try:
super().__getattr__(name)
except AttributeError:
return SafeString('%s.%s}' % (self[:-1], name))

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
return SafeString('%s.%s}' % (self[:-1], name))
return SafeString(f'{self[:-1]}.{name}}}')

As above, Consider using f-string instead.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants